type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'

const fetchData = (url: string, body?: object, method?: HttpMethod) => {
  const urlPrefix = `http://${window.location.hostname}:3001`
  return fetch(`${urlPrefix}${url}`, {
    method: method || 'GET',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    body: body ? JSON.stringify(body) : null
  })
}

export default fetchData
